home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_include / ASM-ARM / BITOPS.H < prev    next >
C/C++ Source or Header  |  1999-09-17  |  3KB  |  94 lines

  1. #ifndef __ASM_ARM_BITOPS_H
  2. #define __ASM_ARM_BITOPS_H
  3.  
  4. /*
  5.  * Copyright 1995, Russell King.
  6.  * Various bits and pieces copyrights include:
  7.  *  Linus Torvalds (test_bit).
  8.  */
  9.  
  10. /*
  11.  * These should be done with inline assembly.
  12.  * All bit operations return 0 if the bit
  13.  * was cleared before the operation and != 0 if it was not.
  14.  *
  15.  * bit 0 is the LSB of addr; bit 32 is the LSB of (addr+1).
  16.  */
  17.  
  18. /*
  19.  * Function prototypes to keep gcc -Wall happy
  20.  */
  21. extern void set_bit(int nr, volatile void * addr);
  22. extern void clear_bit(int nr, volatile void * addr);
  23. extern void change_bit(int nr, volatile void * addr);
  24. extern int test_and_set_bit(int nr, volatile void * addr);
  25. extern int test_and_clear_bit(int nr, volatile void * addr);
  26. extern int test_and_change_bit(int nr, volatile void * addr);
  27. extern int find_first_zero_bit(void * addr, unsigned size);
  28. extern int find_next_zero_bit(void * addr, int size, int offset);
  29.  
  30. /*
  31.  * This routine doesn't need to be atomic.
  32.  */
  33. extern __inline__ int test_bit(int nr, const void * addr)
  34. {
  35.     return ((unsigned char *) addr)[nr >> 3] & (1U << (nr & 7));
  36. }    
  37.  
  38. /*
  39.  * ffz = Find First Zero in word. Undefined if no zero exists,
  40.  * so code should check against ~0UL first..
  41.  */
  42. extern __inline__ unsigned long ffz(unsigned long word)
  43. {
  44.     int k;
  45.  
  46.     word = ~word;
  47.     k = 31;
  48.     if (word & 0x0000ffff) { k -= 16; word <<= 16; }
  49.     if (word & 0x00ff0000) { k -= 8;  word <<= 8;  }
  50.     if (word & 0x0f000000) { k -= 4;  word <<= 4;  }
  51.     if (word & 0x30000000) { k -= 2;  word <<= 2;  }
  52.     if (word & 0x40000000) { k -= 1; }
  53.         return k;
  54. }
  55.  
  56. #ifdef __KERNEL__
  57.  
  58. /*
  59.  * ffs: find first bit set. This is defined the same way as
  60.  * the libc and compiler builtin ffs routines, therefore
  61.  * differs in spirit from the above ffz (man ffs).
  62.  */
  63.  
  64. #define ffs(x) generic_ffs(x)
  65.  
  66. /*
  67.  * hweightN: returns the hamming weight (i.e. the number
  68.  * of bits set) of a N-bit word
  69.  */
  70.  
  71. #define hweight32(x) generic_hweight32(x)
  72. #define hweight16(x) generic_hweight16(x)
  73. #define hweight8(x) generic_hweight8(x)
  74.  
  75. #endif /* __KERNEL__ */
  76.  
  77. #ifdef __KERNEL__
  78.  
  79. #define ext2_set_bit            test_and_set_bit
  80. #define ext2_clear_bit            test_and_clear_bit
  81. #define ext2_test_bit            test_bit
  82. #define ext2_find_first_zero_bit    find_first_zero_bit
  83. #define ext2_find_next_zero_bit        find_next_zero_bit
  84.  
  85. /* Bitmap functions for the minix filesystem. */
  86. #define minix_set_bit(nr,addr)        test_and_set_bit(nr,addr)
  87. #define minix_clear_bit(nr,addr)    test_and_clear_bit(nr,addr)
  88. #define minix_test_bit(nr,addr)        test_bit(nr,addr)
  89. #define minix_find_first_zero_bit(addr,size)    find_first_zero_bit(addr,size)
  90.  
  91. #endif /* __KERNEL__ */
  92.  
  93. #endif /* _ARM_BITOPS_H */
  94.